/**
 * 统计相关 API
 */

import { get } from '@/utils/request'

/**
 * 仪表盘统计数据
 */
export interface DashboardStatistics {
  todayBuilds: number
  todaySuccessBuilds: number
  todayFailedBuilds: number
  avgBuildTimeMinutes: number
  successRate: number
  totalPipelines: number
  activePipelines: number
}

/**
 * 构建趋势数据
 */
export interface BuildTrendData {
  date: string
  successCount: number
  failedCount: number
  cancelledCount: number
  avgDurationMinutes: number
}

/**
 * 获取仪表盘统计数据
 */
export function getDashboardStatistics(): Promise<DashboardStatistics> {
  return get<DashboardStatistics>('/api/Statistics/dashboard')
}

/**
 * 获取构建趋势（最近N天）
 */
export function getBuildTrend(days: number = 7): Promise<BuildTrendData[]> {
  return get<BuildTrendData[]>('/api/Statistics/build-trend', {
    params: { days },
  })
}

/**
 * 获取任务状态分布
 */
export interface TaskStatusDistribution {
  pending: number
  running: number
  success: number
  failed: number
  cancelled: number
}

export function getTaskStatusDistribution(): Promise<TaskStatusDistribution> {
  return get<TaskStatusDistribution>('/api/Statistics/task-status-distribution')
}
